const app = getApp();
var myFn = {
  getUserInfo(){
    wx.getStorage({//获取storage的tokenInfo
      key:"tokenInfo",
      success:(res)=>{
        app.globalData.storage = res.data;
      },
      complete:()=>{
        if(app.globalData.storage==undefined){
          console.log(1);
          wx.navigateTo({
            url: '/pages/login/login',
            success:()=>{
              wx.showToast({
                title: '请先登录',
                icon:'none'
              })
            }
          })
          return;
        }
        wx.request({
          url: app.globalData.serviceUrl+'/user/getUserInfo',
          method:"POST",
          header:{
            "content-type":"application/x-www-form-urlencoded"
          },
          data:{
            token:app.globalData.storage.tokenInfo.token,
            userType:app.globalData.storage.userType
          },
          success:(res)=>{
            app.globalData.userInfo = res.data.data;
          },
          fail:(err)=>{
            console.log(err);
          },
          complete:()=>{
            if(app.globalData.userInfo==null){
              wx.navigateTo({
                url: '/pages/login/login',
                success:()=>{
                  wx.showToast({
                    title: '请先登录',
                    icon:'none'
                  })
                }
              })
              return;
            }
          }
        })
      }
    })
  }
}
module.exports={
  myFn:myFn
}